/**
 * Notes: 管理员模块控制器 - 宠物门店预约小程序
 * Date: 2025-01-27 
 */

const BaseController = require('./base_controller.js');
const AdminService = require('../service/admin_service.js');

class AdminController extends BaseController {

	/**
	 * 获取本店预约列表
	 */
	async getStoreAppointments() {
		// 数据校验
		let rules = {
			date: 'string|max:20|name=日期',
			status: 'int|in:101,201,301,302,401|name=状态筛选',
			page: 'int|min:1|name=页码',
			size: 'int|min:1|max:50|name=每页数量',
		};

		let input = this.validateData(rules);

		let service = new AdminService();
		return await service.getStoreAppointments(
			this._userId,
			input.date || null,
			input.status || null,
			input.page || 1,
			input.size || 20
		);
	}

	/**
	 * 更新预约单状态
	 */
	async updateAppointmentStatus() {
		// 数据校验
		let rules = {
			appointmentId: 'must|string|min:1|max:50|name=预约ID',
			status: 'must|int|in:101,201,301,302,401|name=新状态',
		};

		let input = this.validateData(rules);

		let service = new AdminService();
		return await service.updateAppointmentStatus(this._userId, input.appointmentId, input.status);
	}
}

module.exports = AdminController;
